package org.ala.tiktools.rpc.msg;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 0:push | 1:ack | 2:ping | 3:pong | 4:login | 5:loginSuccess | 6:loginError | 7:loginNo
 *
 * @author ala
 * @date 2025-04-08 09:56
 */
public enum RpcMsgHeadTypeEnums {
    PUSH(0, "push"),
    ACK(1, "ack"),

    PING(2, "ping"),
    PONG(3, "pong"),

    LOGIN(4, "login"),
    LOGIN_SUCCESS(5, "login_success"),
    LOGIN_ERROR(6, "login_error"),
    LOGIN_NO(7, "login_no"),

    TERMINATE(8, "terminate"),
    ;
    private int val;
    private String code;

    RpcMsgHeadTypeEnums(int val, String code) {
        this.val = val;
        this.code = code;
    }

    static Map<Integer, RpcMsgHeadTypeEnums> valMapper;
    public static RpcMsgHeadTypeEnums getInstance(int val) {
        if (valMapper == null) {
            synchronized (RpcMsgHeadTypeEnums.class) {
                if (valMapper == null) {
                    valMapper = Arrays.stream(values()).collect(Collectors.toMap(RpcMsgHeadTypeEnums::getVal, t -> t, (o, n) -> n));
                }
            }
        }
        return valMapper.get(val);
    }

    public int getVal() {
        return val;
    }

    public void setVal(int val) {
        this.val = val;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }
}
